'use strict';

const Service = require('egg').Service;

class UserService extends Service {
    async searchUser(data) {
        try {
            // 查找用户
            const res = await this.app.mysql.select('user', {
                phone: data.name,
                password: data.password
            })

            return {
                code: 1,
                user: res
            }

        } catch(e) {
            return {
                code: 0,
                msg: e.message
            }
        }
    }
  async login(data) {
      try {
        console.log(this.app.mysql)
        const res = await this.service.searchUser(data)
        // const res = await this.app.mysql.select('user', {
        //     phone: data.name,
        //     password: data.password
        // })
        if (res.length > 0) {
            return {
                code: 1
            }
        } else {
            return {
                code: 0
            }
        }
      } catch (e) {
        return {
            code: 0,
            msg: e.message
        }
      }
  }
  
}

module.exports = UserService;
